################################################################################
# Copyright 1999-2010 by Nice, srl.,
# Via Marchesi di Roero, 1
# 14020 Cortanze (AT) - ITALY
# All rights reserved.
#
# This software is the confidential and proprietary information
# of Nice, srl. ("Confidential Information").
# You shall not disclose such Confidential Information
# and shall use it only in accordance with the terms of
# the license agreement you entered into with Nice.
################################################################################


{
    if($1 == "C-") {
        print "<fm:item type=\"folder\" name=\"" getDirName() "\" modified=\"" getTimestamp() "\"/>";
    }
    else {
        if(target == "file" || target == "both") {
            print "<fm:item type=\"file\" name=\"" getFileName() "\" modified=\"" getTimestamp() "\" size=\"" $4 "\"/>";
        }
    }
}


function getDirName() {
   last=split($2,a,"/");
   dirName=a[last];
   return dirName;
}

function getFileName() {
    name=$7;
    for (i = 8; i <= NF; i++) {
        name=name " " $i;
    }
    return name;
}

# Format the date according to 'YYYY-MM-DDTHH:mm:ss+HH:mm' pattern
# The format is RFC 3339 a profile of ISO 8601
# As an example, 2009-09-28T12:17:00+0200
#                2009-07-16.01:02
function getTimestamp() {
    if ( NF < 4 ) {
       iso_timestamp="--";
    }
    else {
       sub("\\.","T",$5);
       iso_timestamp=sprintf("%s:00%s", $5, MYTIMEZONE);
    }

    # Translate months to numbers
    sub("Jan", "01", iso_timestamp);
    sub("Feb", "02", iso_timestamp);
    sub("Mar", "03", iso_timestamp);
    sub("Apr", "04", iso_timestamp);
    sub("May", "05", iso_timestamp);
    sub("Jun", "06", iso_timestamp);
    sub("Jul", "07", iso_timestamp);
    sub("Aug", "08", iso_timestamp);
    sub("Sep", "09", iso_timestamp);
    sub("Oct", "10", iso_timestamp);
    sub("Nov", "11", iso_timestamp);
    sub("Dec", "12", iso_timestamp);

    return iso_timestamp;
#     return "2010-11-13T17:10:00+01:00"
}
